<template>
    <el-breadcrumb class="app-breadcrumb" separator="/">
        <!-- <el-breadcrumb-item v-for="(item)  in levelList" :key="item.path" v-if="item.meta.title">
            <router-link :to="item.redirect||item.path">{{item.meta.title}}</router-link>
        </el-breadcrumb-item> -->
        <el-breadcrumb-item :to="item.path" v-for="item of breadListLast" :key="item.path">
          {{item.name}}
        </el-breadcrumb-item>
    </el-breadcrumb>
</template>

<script>
    export default {
        data() {
            return {
                breadLoadName: '/index',
                breadListIm: [
                    {
                        path: '01',
                        name: '一级'
                    },
                    {
                        path: '02',
                        name: '二级'
                    },
                    {
                        path: '03',
                        name: '三级'
                    },
                ],
                breadListParam:{
                    "1":[{path:"/index",name:"index"}],
                    "2":[{path:"/CreativeCourse",name:"CreativeCourse"}]
                },
                breadBoxIdName:'breadBoxId',
                breadListLast: [],
            }
        },
        mounted() {
            this.loadChange()
        },
        methods: {
            loadChange() {
                this.breadListLast = []
                //获取参数breadBoxId值
                console.log(this.$route.query)
                let breadBoxId = this.$route.query[this.breadBoxIdName]
                console.log(breadBoxId)
                console.log(1111)
                if (this.$route.path.indexOf(this.breadLoadName) === -1) {
                        console.log('面包屑路由地址breadLoadName没有配置正确！')
                } else {
                    let breadListAgo = this.$route.path.split(this.breadLoadName)
                    // let breadListAgo = '/index/indexSchool/breadList/01/02/03'.split(this.breadLoadName)
                    let breadList = breadListAgo[1].split('/')
                    let obje = {}
                    let breadIndex = ''
                    //删除掉数组的前1个，提升遍历性能
                    breadList.splice(0, 1)
                    //考虑到顺序问题，只能先遍历breadList,再遍历breadListIm
                    for (let p of breadList) {
                        for (let q of this.breadListIm) {
                            if (p === q.path) {
                                breadIndex += '/' + q.path
                                obje.path = breadListAgo[0] + this.breadLoadName + breadIndex
                                obje.name = q.name
                                this.breadListLast.push(obje)
                                obje = {}
                            }
                        }
                    }
                }
                // 打印路由配置
                // console.log(JSON.stringify(this.breadListLast))
            }
        },
        watch: {
            $route(to, from) {
                this.loadChange()
                // console.log(to.path);
            }
        }
    }
</script>
